package com.atguigu.vod.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;

@Api(description = "视频相关操作")
@RestController
@RequestMapping("/eduvod/video")
//原来需要在Controller上面加上@CrossOrigin解决跨域问题，现在gateway已经处理了
public class VodController {

    @Autowired
    private VodService vodService;

    @ApiOperation(value = "实现视频上传")
    @PostMapping("/uploadVideo")
    public R uploadVideo(MultipartFile file) throws IOException {
        return vodService.testUploadVideo(file);
    }

    /*根据视频id删除阿里云里面的视频*/
    @ApiOperation(value = "根据视频id删除阿里云里面的视频")
    @DeleteMapping("removeAliVideo/{videoId}")
    public boolean removeAliVideo(@PathVariable(value = "videoId") String videoId){
        return vodService.removeAliVideo(videoId);
    }


    /*根据ids删除阿里云里面的多个视频*/
    @ApiOperation(value = "根据ids删除阿里云里面的多个视频")
    @DeleteMapping("removeAliVideos")
    public R removeAliVideos(@RequestParam("videoIds") ArrayList<String> videoIds){
        boolean flag=vodService.removeAliVideos(videoIds);
        if(flag==true){
            return R.ok();
        }
        return R.error();
    }

    /*根据视频id获取视频播放凭证，传递给前端播放视频*/
    @ApiOperation(value = "根据视频videoSourceId播放视频")
    @GetMapping("getplayauth/{videoSourceId}")
    public R getPlayAuth(@PathVariable(value = "videoSourceId") String videoSourceId){
        return vodService.getPlayAuth(videoSourceId);
    }


}